import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_devices/routes/index.dart';
import 'package:smart_devices/ui/draw_under_line.dart';
import 'package:smart_devices/ui/max_line_wrap.dart';
import 'package:smart_devices/ui/scroll_refresh_config.dart';
import 'package:smart_devices/utils/colors.dart';
import 'package:smart_devices/utils/styles.dart';

import 'task_logic.dart';

class TaskComponent extends GetView<TaskLogic> {
  TaskComponent({super.key}) {
    Get.lazyPut(() => TaskLogic());
  }


  @override
  Widget build(BuildContext context) {
    return Obx(() => scrollRefreshConfig(context));
  }

  Widget scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: controller.refreshController,
      onRefresh: controller.onRefresh,
      onLoading: controller.onLoading,
      child: listViewBuilder(context),
    );
  }

  Widget listViewBuilder(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext c, int index) {
        return DrawUnderLine(
            child: InkWell(
              onTap: () {
                Get.toNamed(Routes.deviceUpkeepInfo, arguments: {
                  'task': controller.pageList[index],
                  'details': controller.details.value,
                });
              },
              child: Container(
                padding: const EdgeInsets.symmetric(horizontal: 15),
                margin: index == 0 ? const EdgeInsets.only(top: 15) : EdgeInsets.zero,
                decoration: const BoxDecoration(color: Colors.white),
                child: Column(
                  children: [
                    Container(
                      height: 40,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        controller.pageList[index].title,
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color0052, fontSize: 16, fontWeight: FontWeight.w700),
                      ),
                    ),
                    Container(
                      height: 30,
                      alignment: Alignment.centerLeft,
                      child: MaxLineWrap(
                        maxLine: 1,
                        itemAlignment: MaxLineWrapAlignment.start,
                        children: [
                          Text(
                            '任务编号',
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 13),
                          ),
                          Text(
                            controller.pageList[index].taskNo,
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.colorAaaa, fontSize: 13),
                          )
                        ],
                      ),
                    ),
                    Container(
                      height: 30,
                      alignment: Alignment.centerLeft,
                      child: MaxLineWrap(
                        maxLine: 1,
                        itemAlignment: MaxLineWrapAlignment.start,
                        children: [
                          Text(
                            '设备名称',
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 13),
                          ),
                          Text(
                            controller.pageList[index].name,
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.colorAaaa, fontSize: 13),
                          )
                        ],
                      ),
                    ),
                    Container(
                      height: 30,
                      alignment: Alignment.centerLeft,
                      child: MaxLineWrap(
                        maxLine: 1,
                        itemAlignment: MaxLineWrapAlignment.start,
                        children: [
                          Text(
                            '设备编号',
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 13),
                          ),
                          Text(
                            controller.pageList[index].code,
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.colorAaaa, fontSize: 13),
                          )
                        ],
                      ),
                    ),
                    Container(
                      height: 30,
                      alignment: Alignment.centerLeft,
                      child: MaxLineWrap(
                        maxLine: 1,
                        itemAlignment: MaxLineWrapAlignment.start,
                        children: [
                          Text(
                            '存放位置',
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 13),
                          ),
                          Text(
                            controller.pageList[index].location,
                            overflow: TextOverflow.ellipsis,
                            maxLines: 1,
                            style:
                            StylesUtils.customTextStyle(color: ColorsUtils.colorAaaa, fontSize: 13),
                          )
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 40,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            controller.pageList[index].addTime,
                            style:
                            StylesUtils.customTextStyle(fontSize: 13, color: ColorsUtils.color3333),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ));
      },
      itemCount: controller.pageList.length,
      itemExtent: 250,
    );
  }
}
